<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Field_Dropdown extends Field_Abstract {

  public function getHtml() {
    return sprintf('<select name="%s" %s> %s </select>', $this->getName(), $this->getExtras(), $this->_optionToHtml());
  }

  protected function _optionToHtml() {

    $value = $this->getValue();
    $opts = array();
    foreach ($this->getOptions() as $v => $t) {
      $opts[] = sprintf('<option value="%s" %s>%s</option>', $v, $value == $v ? 'selected="selected"' : '', $t);
    }
    return implode("", $opts);
  }

  protected function getOptions() {
    return (array) $this->_params['options'];
  }

}
